package com._520it.wms.web.controller;

import com._520it.wms.domain.Client;
import com._520it.wms.query.QueryObject;
import com._520it.wms.service.IClientService;
import com._520it.wms.util.JSONResult;
import com._520it.wms.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by HASEE on 2017/11/14.
 */
@Controller
@RequestMapping("/client")
public class ClientContorller {
    @Autowired
    private IClientService clientService;

    @RequestMapping("/list")
    @RequiredPermission("客户列表")
    public String list(Model model, QueryObject qo) {
        //int a = 1/0; 异常解析器
        model.addAttribute("pageResult", clientService.query(qo));
        return "/client/list";
    }

    @RequestMapping("/input")
    @RequiredPermission("客户编辑")
    public String input(Long id, Model model) {
        if (id != null) {
            Client client = clientService.get(id);
            model.addAttribute("client", client);
        }
        return "/client/input";
    }

    @RequestMapping("delete")
    @RequiredPermission("客户删除")
    @ResponseBody
    public JSONResult delete(Long id) {
        if (id != null) {
            clientService.delete(id);
        }
        return new JSONResult();
    }

    @RequestMapping("/saveOrUpdate")
    @RequiredPermission("客户新增/更新")
    @ResponseBody
    public JSONResult saveOrUpdate(Client client) {
        clientService.saveOrUpdate(client);
        return new JSONResult();
    }


}
